package com.bishe.supermarket.controller;

import com.bishe.supermarket.pojo.Staff;
import com.bishe.supermarket.pojo.vo.Status;
import com.bishe.supermarket.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class StaffController {

    @Autowired
    StaffService staffService;
    //转换地址
    @RequestMapping("staffDo")
    public String staffDo(HttpSession httpSession){

        List<Staff> list = staffService.selectAll();

        httpSession.setAttribute("staffList",list);

        return "staff";
    }

    //用来姓名查询
    @RequestMapping("selectName")
    public String selectName(String staffName,HttpSession httpSession){

       List<Staff> list = staffService.selectByName(staffName);

       httpSession.setAttribute("staffName",list);
       return "selectStaffName";
    }
    //添加员工信息页面跳转

    @RequestMapping("addStaffs")
    public String addStaffs(){


        return "addStaff";
    }

    @RequestMapping("receiveStaff")
    public String receiveStaff(String staffName,int staffAge,HttpSession httpSession){

        Status status = staffService.addStaff(staffName,staffAge);

        httpSession.setAttribute("statusStaff",status);

       return "addStaffMsg";
    }
    //删除员工信息

    @RequestMapping("deleteSt")
    public String deleteSt(HttpSession httpSession){

        List<Staff> staff = staffService.selectAll();
        httpSession.setAttribute("staffName",staff);

        return "deleteStaff";
    }

    @RequestMapping("receiveDelete")
    public String receiveDelete(String staffName,HttpSession httpSession){

     Status status =  staffService.deleteStaff(staffName);
     httpSession.setAttribute("staffMsg",status);
     return "deleteStaffMsg";
    }
}
